<?php

defined('ROOT') or die('No direct script access.');
//echo "<!DOCTYPE html> <html>";
include ("config.php");
include_once ($config['SYSPATH'] . "/helpers/constructforms.php");
$baseurl = $config['BASEPATH'];
if ($controller['name'] != "") {
    if ($controller['act'] != "")
        echo "<form action='$baseurl/{$controller['name']}/{$controller['act']}' method=post>";
    else
        echo "<form id='frm'>";
} else {
    echo "<form>";
}
echo "<table>";
foreach ($arr_cols as $col) {
    $disabled = (isset($col['disabled']) ? $col['disabled'] : 0);
    echo "<tr>";
    if ($col['type'] == 'edit') {
        echo "<td>" . $col['title'] . "</td>";
        if (!isset($col['size'])){
            $col['size'] = 50;
        }
        echo "<td>" . form_edit($col['name'], $col['size'], $data[$col['name']], "", $disabled) . "</td>";
    }
    if ($col['type'] == 'select') {
        $title_col = "title";
        $multiple = false;
        if (isset($col['title_col']))
            $title_col = $col['title_col'];
        if (isset($col['multiple'])) {
            $multiple = $col['multiple'];
            $size_select = 5;
            if (isset($col['size'])) {
                $size_select = $col['size'];
            }
        }
        $col_name = str_replace("_select", "", $col['name']);
        echo "<td>" . $col['title'] . "</td>";
        if ($multiple) {
            echo "<td>" . form_select_multiple($col_name, $data[$col_name], $col['data'], $size_select, "", $disabled, $title_col) . "</td>";
        } else {
            echo "<td>" . form_combo($col_name, $data[$col_name], $col['data'], "", $disabled, $title_col) . "</td>";
        }
    }
    if ($col['type'] == 'text') {
        echo "<td>" . $col['title'] . "</td>";
        echo "<td>" . form_text($col['name'], $col['rows'], $col['cols'], $data[$col['name']], "", $disabled) . "</td>";
    }
    if ($col['type'] == 'checkbox') {
        echo "<td>&nbsp;</td>";
        echo "<td>" . form_checkbox($col['title'], $col['name'], $data[$col['name']], "", $disabled) . "</td>";
    }
    if ($col['type'] == 'hidden') {
        echo "<td><input type=hidden value='{$data[$col['name']]}' name='{$col['name']}' id='{$col['name']}'></td>";
    }
    echo "</tr>";
}
echo "</table>";
if ($controller['name'] != "") {
    echo "<button type=submit class=btn>Сохранить</button>";
}
echo "</form>";
?>